#include "stdafx.h"
#include "DefenceStatusPropertyPage.h"
#include "Status.h"
#include "Property.h"

#include <utility/Config.h>
#include <utility/Streams.h>

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif

namespace serika
{
	namespace dq
	{
		DefenceStatusPropertyPage::DefenceStatusPropertyPage(PropertyTemplate* tmpl)
			: PropertyPage(tmpl)
		{
		}

		DefenceStatusPropertyPage::~DefenceStatusPropertyPage()
		{
		}

		void DefenceStatusPropertyPage::OnInitialize()
		{
			this->CreateCombo(mCombo, CBS_DROPDOWNLIST);
			const std::vector<Status>& attributes = Status::GetStatuses();
			for (std::vector<Status>::const_iterator itr = attributes.begin();
				itr != attributes.end(); ++itr)
			{
				mCombo.InsertString(itr->GetId()-1, itr->GetName().c_str());
			}
			this->CreateEdit(mEdit, true);
		}

		void DefenceStatusPropertyPage::DoLayout(ut::Config* config)
		{
			this->Layout(&mCombo, config, _T("Combo"));
			this->Layout(&mEdit, config, _T("Edit"));
		}

		Property* DefenceStatusPropertyPage::CreateProperty()
		{
			int id = mCombo.GetCurSel() + 1;
			CString text;
			mEdit.GetWindowText(text);
			ut::Sstream ss;
			ss << text.GetBuffer();
			int attr = 0;
			ss >> attr;
			mCombo.GetWindowText(text);
			return Property::NewProperty(0, id, attr, 0, ut::String(text), mTmpl);
		}

		void DefenceStatusPropertyPage::OnActivate()
		{
		}

		void DefenceStatusPropertyPage::OnDeactivate()
		{
		}
	}
}
